﻿using System;
using System.Collections.Generic;

using Fuse8.DomainFramework.Common;

namespace Fuse8.DomainFramework.DataAccess.SqlDatabase
{
    /// <summary>
    /// 
    /// </summary>
    public static class SqlMapExtension
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sqlMap"></param>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        public static SqlMap<T> WithIgnoreTo<T>(this SqlMap<T> sqlMap, string propertyName) where T : class, new()
        {
            Guard.ArgumentNotNull(sqlMap, "sqlMap");
            Guard.ArgumentNotEmpty(propertyName, "propertyName");

            if (sqlMap.IgnoreToProperties == null)
            {
                sqlMap.IgnoreToProperties = new List<string>();
            }

            var ignoreProperties = sqlMap.IgnoreToProperties;

            if (!ignoreProperties.Contains(propertyName))
            {
                ignoreProperties.Add(propertyName);
            }

            return sqlMap;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sqlMap"></param>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        public static SqlMap<T> WithIgnoreFrom<T>(this SqlMap<T> sqlMap, string propertyName) where T : class, new()
        {
            Guard.ArgumentNotNull(sqlMap, "sqlMap");
            Guard.ArgumentNotEmpty(propertyName, "propertyName");

            if (sqlMap.IgnoreFromProperties == null)
            {
                sqlMap.IgnoreFromProperties = new List<string>();
            }

            var ignoreProperties = sqlMap.IgnoreFromProperties;

            if (!ignoreProperties.Contains(propertyName))
            {
                ignoreProperties.Add(propertyName);
            }

            return sqlMap;
        }
    }
}
